<template>
  <div class="herader ww">
    <div class="h_left">
      <img src="@/assets/images/logo.png" alt="">
      <span>天气数据采集系统</span>
    </div>
    <div class="h_center">
      <template v-if="!isLogin">
        <a @click="$router.push('/login')">登录</a>
        |
        <a @click="$router.push('/reg')">注册</a>
        |
      </template>
      <template v-if="isLogin">
        <a>已登录</a>
        |
        <a @click="outLogin">退出</a>
        |
      </template>
      <a @click="$router.push('/')">首页</a>
      |
      <a @click="$router.push('/message')">留言</a>
      |
      <a>关于我们</a>
    </div>
  </div>
</template>

<script>
  import {getToken} from '@/utils/auth'
  import {MessageBox} from "element-ui";
  import {removeToken} from '@/utils/auth'

  export default {
    name: "head-view",
    data() {
      return {
        isLogin: false
      }
    },
    created() {
      // 是否需要设置 token
      if (getToken()) {
        this.isLogin = true;
      } else {
        this.isLogin = false;
      }
    },
    methods: {
      outLogin() {
        MessageBox.confirm('是否确认退出', '系统提示', {
            confirmButtonText: '退出',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          removeToken();
          location.href = '/';
        })
      }
    }
  }
</script>

<style scoped>
  @import "index.scss";
</style>
